let delItem;
let deleteDialog = $(`
	<div class="modal fade" tabindex="-1">
		<!-- 删除对话框 -->
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="exampleModalLabel">确认删除获奖信息</h5>
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					确认要删除吗？
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary"
						data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary _save">确认</button>
				</div>
			</div>
		</div>
	</div>`);
	$("body").append(deleteDialog);
	let btn = deleteDialog[0].querySelector("._save");

	btn.onclick = function() {
		//验证输入参数
		let param = new URLSearchParams();
		param.append("medalId",delItem.medalId);
		console.info(param.toString());
		fetch("medal-delete.let", {
			method: 'POST',
			mode: 'cors',
			cache: 'no-cache',
			credentials: 'include',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded',
			},
			redirect: 'follow',
			referrerPolicy: 'no-referrer',
			body: param
		}).then(r => r.json()).then(data => {
			if (data.ok) {
				deleteDialog.modal('hide');
				window.postMessage("loadData");//发送消息
			} else {
				alert(data.msg);
			}
			console.debug(data);
		}).catch(e => {
			console.error(e);
		});
	}


export default function(item) {
	delItem = item;
	deleteDialog.modal('show');
	
}